package com.biscuit.page.basicservice.design.websocket.register.strategy;

import com.biscuit.page.basicservice.design.websocket.register.AbstractWebSocketRegister;
import com.biscuit.page.basicservice.design.websocket.register.AiChatSessionWebSocketRegisterContext;
import com.biscuit.page.basicservice.websocket.ai_chat.AiChatSessionWebSocketContext;
import com.biscuit.page.basicservice.websocket.ai_chat.AiChatSessionWebSocketHandler;

/**
 * @author biscuit
 * @create 2024年08月01日 9:28
 */
public class AiChatSessionWebSocketRegisterHandlerStrategy implements WebSocketRegisterHandlerStrategy {

    @Override
    public void register(AbstractWebSocketRegister abstractRegisterContext) {
        // 将类型转换为实际入参类型
        AiChatSessionWebSocketRegisterContext registerContext = (AiChatSessionWebSocketRegisterContext) abstractRegisterContext;

        // ai 会话 websocket 上下文对象
        AiChatSessionWebSocketContext context = AiChatSessionWebSocketContext.builder()
                .session(registerContext.getSession())
                .sessionId(registerContext.getSessionId())
                .build();

        // 存储 websocket 对象
        AiChatSessionWebSocketHandler.addContext(context);
    }

}
